<template>
    <div>
        <el-input :placeholder="placeholder" :disabled="!edit" v-model="newValue" style="color: black">
            <template slot="prepend">{{field}}</template>
            <template slot="append" v-if="append">
                <template v-if="!edit">
                    <el-button @click="edit = true">编辑</el-button>
                </template>
                <template v-else>
                    <el-button icon="el-icon-check" @click="updateField"></el-button>
                    <el-button icon="el-icon-close" @click="cancel"></el-button>
                </template>
            </template>
        </el-input>
    </div>
</template>

<script>
    export default {
        name: "LineInfo",
        model: {
            prop: "value",
            event: "change",
        },
        props: {
            placeholder:{
                type: String,
                required: false,
                default: "请输入内容"
            },
            field: {
                type: String,
                required: true,
            },
            value: {
                type: String,
                required: true,
            },
            append:{
                type: Boolean,
                default: true,
            },

        },
        data(){
            return{
                edit: false,
            }
        },
        computed: {
            newValue:{
                get: function(){
                    return this.value;
                },
                set: function(value){
                    this.$emit("change", value);
                }
            }
        },
        methods:{
            updateField(){
                this.$emit("updateField", this.closeEdit)
            },
            closeEdit(){
                this.edit = false;
            },
            cancel(){
                this.closeEdit();
                this.$emit("resetField")
            }
        }
    }
</script>

<style scoped>

</style>